/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package connection;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author WindWalk
 */
public class connectionSQLServer {
     final String server = "WINDWALK-PC\\SQLEXPRESS:1433";
     final String databaseName = "BugSystem";
     final String user = "sa";
     final String password = "123456";
     Connection con = null;
     //Statement st = null;
     public String getConnectionString()
     {
         return "jdbc:sqlserver://"+server+";"
                 +"databaseName = "+databaseName+";"
                 +"username = "+user+";"
                 +"password = "+password;
     }
    public Connection connect()
    {
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(getConnectionString());
        } catch (SQLException | ClassNotFoundException ex) {
            JOptionPane.showMessageDialog(null, "Can not connect to database!","Database Error", JOptionPane.ERROR_MESSAGE);
        }
        return con;
    }
    public ResultSet excuteSQL(String sql) throws SQLException
    {
            
       Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
       ResultSet rs = st.executeQuery(sql);
         return rs;   
        }
    public void closeConnect() throws SQLException
    {
        if(con != null)
            con.close();
    }
    public void executeUpdateSQL(String sql) throws SQLException
    {
        PreparedStatement pstm = con.prepareStatement(sql);
        pstm.executeUpdate();
    }
        
    }

